<?= view("home.common.header") ?>
    <div class="container-fluid">
       <div class="row">
            <div class="col-xs-12 col-sm-12 bottom-line">
                <i class="glyphicon glyphicon-chevron-right jt"></i><span class="headfont">个人信息设置</span>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12">
                <form id="setinfo" enctype="multipart/form-data" method="post">
                    <input class="form-control" type="text" name="phone" value="<?= $user->phone ?>" <?php if ($user->isver == 1 && !empty($user->phone)): ?>disabled="disabled"<?php endif; ?> placeholder="--个人联系电话--">
                    <input class="form-control" type="text" name="name" value="<?= $user->name ?>" <?php if ($user->isver == 1): ?>disabled="disabled"<?php endif; ?> placeholder="--身份证姓名--">
                    <input class="form-control" type="text" name="cardnumber" value="<?= $user->cardnumber ?>" <?php if ($user->isver == 1): ?>disabled="disabled"<?php endif; ?> placeholder="--身份证号码--">
<!--                    <div class="col-xs-6 col-sm-6 mtop15">
                        <a href="#" class='btn btn-orange' onclick="return uploadF('idfront')">身份证正面</a>
                        <input name="idfront" id="idfront" data-img="frontimg" type="file" class="hidden"/>
                    </div>
                    <div class="col-xs-6 col-sm-6 mtop15">
                        <a href="#" class='btn btn-orange' onclick="return uploadF('idback')">身份证反面</a>
                        <input name="idback" id="idback" data-img="backimg" type="file" class="hidden"/>
                    </div>
                    <p class="help-block mtop15 pleft15">(最大支持上传3M文件, 文件类型jpg、png)</p>
                    <p class="help-block mtop15 pleft15">(文件太大,请用手机打开图片然后截屏之后上传)</p>
                    <div class="col-xs-6 col-sm-6 mtop15">
                        <img src="<?=$user->strCard(1)?>" id="frontimg"/>
                    </div>
                    <div class="col-xs-6 col-sm-6 mtop15">
                        <img src="<?=$user->strCard(2)?>" id="backimg"/>
                    </div>-->
                </form>
                <?php if ($user->isver != 1 || empty($user->phone)): ?>
                <a class="btn btn-blue form-control mtop15" href="#" onclick="return subForm()">提交修改</a>
                <?php endif; ?>
                <a class="btn btn-orange form-control mtop15" href="<?=url('home/index/index?ptype=1')?>">去购买宽带</a>
                <a class="btn btn-danger form-control mtop15" href="<?=url('home/login/logout')?>">退出账户</a>
            </div>
            <div class="col-xs-12 bqf col-sm-12 text-center"><?=config("global.site.global.footer")?></div>
        </div>
    </div>
    <script type="text/javascript" src="<?= asset("js/jquery.form.js")?>"></script>
    <script>
		function uploadF(type) {
			$('#'+type).trigger('click');
			return false;
		};
		$("#idfront,#idback").change(function() {
			var imgId = $(this).attr('data-img');
			showImg(event, imgId);
		});
		
		function showImg(evt, imgId) {
			if (!window.FileReader) return;
			var files = evt.target.files;
			for (var i = 0, f; f = files[i]; i++) {
				if (!f.type.match('image.*')) {
					continue; 
				}
				var reader = new FileReader();
				reader.onload = (function(theFile) {  
					return function(e) { 
						// img 元素  
						document.getElementById(imgId).src = e.target.result;  
					};  
				})(f);  
				reader.readAsDataURL(f);  
			}  
		}
        function subForm() {
            var reg = /^1[3587]\d{9}$/;
            if ($('input[name=phone]').val() == '' || !reg.test($('input[name=phone]').val())) {
                layer.open({
                    content: '请正确填写联系手机',
                    style: 'background-color:#09C1FF; color:#fff; border:none;',
                    time: 2
                });
                $('input[name=phone]').focus();
                return false;
            }
            if ($('input[name=name]').val() == '') {
                layer.open({
                    content: '请填写身份证姓名',
                    style: 'background-color:#09C1FF; color:#fff; border:none;',
                    time: 2
                });
                $('input[name=name]').focus();
                return false;
            }
            if ($('input[name=cardnumber]').val() == '' || $('input[name=cardnumber]').val().length != 18) {
                layer.open({
                    content: '请正确填写身份证号码',
                    style: 'background-color:#09C1FF; color:#fff; border:none;',
                    time: 2
                });
                $('input[name=cardnumber]').focus();
                return false;
            }
//            if ($("input[name=idfront]").val() == '' && '<?= $user->idfront ?>'=='') {
//                layer.open({
//                    content: "请上传身份证正面照片",
//                    style: 'background-color:#09C1FF; color:#fff; border:none;',
//                    time: 2
//                });
//                return false;
//            }
//            if ($("input[name=idback]").val() == '' && '<?= $user->idback ?>'=='') {
//                layer.open({
//                    content: '请上传身份证反面照片',
//                    style: 'background-color:#09C1FF; color:#fff; border:none;',
//                    time: 2
//                });
//                return false;
//            }
            $("#setinfo").ajaxSubmit(function(data) {
                layer.open({
                    content: data.info,
                    style: 'background-color:#09C1FF; color:#fff; border:none;',
                    time: 2
                });
                if (data.status == 1) {
                    window.setTimeout(function(){
                        window.location.reload();
                    }, 2000);
                }
            });
            return false;
        }
	</script>
<?= view("home.common.footer") ?>
